// $Id: networkslotalloc.h 72 2004-12-02 15:03:28Z jonas $
#ifndef NETWORKSLOTALLOC_H
#define NETWORKSLOTALLOC_H

#include "network.h"

const int slotSize = 10000;

/**
 * This network simulation model hands out a number of fixed size slots to all nodes. The quantity of slots received depends on the nodes bandwith (up and down separatly).
 * The algorithm iterate thu all transfers and removes an upload slot from the sending node, and a download slot from the receiving node. When it run out of transfers, it starts over from the top again. The algorithm continues until all limiting slots are removed (the nodes dont have any bandwith left).
 */
class NetworkSlotAlloc : public Network {
public:
	NetworkSlotAlloc(list<Node *> *);
	//~NetworkSlotAlloc();

	void transfer();

private:
	/**
	 * This class keep track on how many slots a node has remaining during the network transfer process.
	 */
	class NodeSlotWrapper {
	public:
		NodeSlotWrapper();
		NodeSlotWrapper(Node *);
		~NodeSlotWrapper();

		Node *m_node;
		int m_slotsUpCount;
		int m_slotsDownCount;

		/**
		* @todo Documentation goes here...
		*/
		// TODO: Depricated
		/*class TransferSlotWrapper {
		public:
			TransferSlotWrapper(Transfer *);

			Transfer *m_transfer;
			int m_slotCount;
		};*/

		Transfer *getNextTransfer();
		void resetTransferIterator();

		/*list<TransferSlotWrapper *> m_transfers;
		list<TransferSlotWrapper *>::iterator m_transferIterator;*/
		int m_transferIterator;
	};
	map<Node *, NodeSlotWrapper> m_nodeWrappers;

	bool transferChain(NodeSlotWrapper *, Transfer *);
};

#endif
